from quto_auto.db.dbhandle import DbHandle


class DbCustomer:

    def __init__(self):
        self.dbhandle = DbHandle(host='172.16.113.156')

    # 添加客户
    def insert_customer_info(self, customerNo):
        self.dbhandle.update_data("insert into tb_customer value(customerNO=%s",[customerNo])

    # 修改客户
    def put_customer_info(self, customerNo,customername):
        self.dbhandle.update_data("update tb_customer set customerName=%s where customerNO=%s",[customername,customerNo])

    # 查询客户
    def sec_customer_info(self, customerNo):
        res=self.dbhandle.search_data("select * from tb_customer where customerNO=%s",[customerNo])
        res_cus=list(res[0].values()) #返回第一条数据
        res_cus.sort() #排序
        return res_cus

    #删除客户
    def del_customer_info(self,customerNo):
        self.dbhandle.update_data("delete from tb_customer where customerNO={}".format(customerNo))

    # 删除多条客户信息
    def del_customers_info_lst(self, lst):
        for no in lst:
            self.del_customer_info(no)



# if __name__ == '__main__':
#     db_customer=DbCustomer()
#     db_customer.del_customer_info('39')